home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Mac / scripts / PackLibDir.py < prev    next >
Encoding:
Python Source  |  1996-07-10  |  1.3 KB  |  50 lines  |  [TEXT/Pyth]

  1. #
  2. # Turn a pyc file into a resource file containing it in 'PYC ' resource form
  3. from Res import *
  4. import Res
  5. from Resources import *
  6. import os
  7. import macfs
  8. import sys
  9. import py_resource
  10.  
  11. error = 'mkpycresourcefile.error'
  12.  
  13. def mkpycresourcefile(src, dst):
  14.     """Copy pyc file/dir src to resource file dst."""
  15.     
  16.     if not os.path.isdir(src) and src[-4:] <> '.pyc':
  17.             raise error, 'I can only handle .pyc files or directories'
  18.     fsid = py_resource.create(dst)
  19.     if os.path.isdir(src):
  20.         handlesubdir(src)
  21.     else:
  22.         id, name = py_resource.frompycfile(src)
  23.         print 'Wrote %d: %s %s'%(id, name, src)
  24.     CloseResFile(fsid)
  25.             
  26. def handlesubdir(srcdir):
  27.     """Recursively scan a directory for pyc files and copy to resources"""
  28.     src = os.listdir(srcdir)
  29.     for file in src:
  30.         file = os.path.join(srcdir, file)
  31.         if os.path.isdir(file):
  32.             handlesubdir(file)
  33.         elif file[-4:] == '.pyc':
  34.             id, name = py_resource.frompycfile(file)
  35.             print 'Wrote %d: %s %s'%(id, name, file)
  36.     
  37. if __name__ == '__main__':
  38.     args = sys.argv[1:]
  39.     if not args:
  40.         ifss, ok = macfs.GetDirectory('Select root of tree to pack:')
  41.         if not ok:
  42.             sys.exit(0)
  43.         args = [ifss.as_pathname()]
  44.     for ifn in args:
  45.         ofss, ok = macfs.StandardPutFile('Output for '+os.path.split(ifn)[1])
  46.         if not ok:
  47.             sys.exit(0)
  48.         mkpycresourcefile(ifn, ofss.as_pathname())
  49.     sys.exit(1)            # So we can see something...
  50.